using System.ComponentModel;
using System.Collections.Generic;
using Blazing.BusinessObjects.Queries;
using Iesi.Collections.Generic;
using Blazing.BusinessObjects.Locations;

namespace Blazing.WebFacade
{
    [System.ComponentModel.DataObject]
    public class AddressController
    {
        #region Address
        [DataObjectMethodAttribute(DataObjectMethodType.Delete)]
        public Address DeleteAddress(Address address)
        {
            address.Delete();
            address.Save();
            return address;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert)]
        public Address NewAddress(Address address)
        {
            address.Save();
            return address;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update)]
        public Address UpdateAddress(Address address)
        {
            address.Save();
            return address;
        }

        //[DataObjectMethodAttribute(DataObjectMethodType.Select)]
        //public ISet<Address> GetBuildingAddresses(int buildingId)
        //{
        //    Building obj = Building.Load(buildingId);
        //    return obj != null ? obj.Addresses : null;
        //}
        #endregion

        #region AddressType
        [DataObjectMethodAttribute(DataObjectMethodType.Delete)]
        public void DeleteAddressType(AddressType addressType)
        {
            addressType.Delete();
            addressType.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert)]
        public int NewAddressType(AddressType addressType)
        {
            addressType.Save();
            return addressType.ID;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update)]
        public void UpdateAddressType(AddressType addressType)
        {
            addressType.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select)]
        public IList<AddressType> GetAddressesTypes()
        {
            return AddressType.Search(QrySearchAddressTypes.Query());
        }
        #endregion

        #region State
        [DataObjectMethodAttribute(DataObjectMethodType.Delete)]
        public void DeleteState(State state)
        {
            state.Delete();
            state.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert)]
        public int NewState(State state)
        {
            state.Save();
            return state.ID;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update)]
        public void UpdateState(State state)
        {
            state.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select)]
        public IList<State> GetStates()
        {
            return State.Search(QrySearchStates.Query());
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select)]
        public ISet<State> GetStates(int countryID)
        {
            Country obj = Country.Load(countryID);
            return obj != null ? obj.States : null;
        }
        #endregion

        #region Country
        [DataObjectMethodAttribute(DataObjectMethodType.Delete)]
        public void DeleteCountry(Country country)
        {
            country.Delete();
            country.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert)]
        public int NewCountry(Country country)
        {
            country.Save();
            return country.ID;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update)]
        public void UpdateCountry(Country country)
        {
            country.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select)]
        public IList<Country> GetCountries()
        {
            return Country.Search(QrySearchCountries.Query());
        }
        #endregion

        #region Currency
        [DataObjectMethodAttribute(DataObjectMethodType.Delete)]
        public void DeleteCurrency(Currency currency)
        {
            currency.Delete();
            currency.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert)]
        public int NewCurrency(Currency currency)
        {
            currency.Save();
            return currency.ID;
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update)]
        public void UpdateCurrency(Currency currency)
        {
            currency.Save();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select)]
        public IList<Currency> GetCurrencies()
        {
            return Currency.Search(QrySearchCurrencies.Query());
        }
        #endregion
    }
}
